home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / Snippets / Toolbox / WindowColors / WindowColors.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-15  |  3.5 KB  |  157 lines  |  [TEXT/KAHL]

  1. /****************************************************************************/
  2. /*                                                                            */
  3. /*    Application:    WindowColors                                            */
  4. /*                                                                            */
  5. /*    Description:    This application displays the default window colors        */
  6. /*                    stored in the System's 'wctb' resource.  Note that        */
  7. /*                    this app is 7.0 only, since it only recognizes the 7.0    */
  8. /*                    version of the resource.                                */
  9. /*                                                                            */
  10. /*    Files:            WindowColors.π                                            */
  11. /*                    WindowColors.c                                            */
  12. /*                                                                            */
  13. /*    Programmer:        Edgar Lee                                                */
  14. /*    Organization:    Apple Computer, Inc.                                    */
  15. /*    Department:        Developer Technical Support, DTS                        */
  16. /*    Language:        C (Think C version 5.0.1)                                */
  17. /*    Date Created:    02-19-92                                                */
  18. /*                                                                            */
  19. /****************************************************************************/
  20.  
  21. /* Constant Declarations */
  22.  
  23. #define    WWIDTH        375
  24. #define    WHEIGHT        155
  25.  
  26. #define WLEFT        (((screenBits.bounds.right - screenBits.bounds.left) - WWIDTH) / 2)
  27. #define WTOP        (((screenBits.bounds.bottom - screenBits.bounds.top) - WHEIGHT) / 2)
  28.  
  29. /* Global Variable Definitions */
  30.  
  31. #define    TOTALWINCOLORS    13
  32.  
  33. CTabHandle    gWindowCTable;
  34.  
  35. Str255    gTitles[TOTALWINCOLORS] =
  36. {
  37.     "\pContent", "\pFrame", "\pText", "\pHilite",
  38.     "\pTitleBar", "\pHiliteLight", "\pHiliteDark", "\pTitleBarLight",
  39.     "\pTitleBarDark", "\pDialogLight", "\pDialogDark", "\pTingeLight",
  40.     "\pTingeDark"
  41. };
  42.  
  43.  
  44. void initMac();
  45. void createWindow();
  46. void drawWindowColors();
  47. void doEventLoop();
  48.  
  49. main()
  50. {
  51.     initMac();
  52.     
  53.     createWindow();
  54.     
  55.     doEventLoop();
  56. }
  57.  
  58. void initMac()
  59. {
  60.     MaxApplZone();
  61.  
  62.     InitGraf( &thePort );
  63.     InitFonts();
  64.     InitWindows();
  65.     InitMenus();
  66.     TEInit();
  67.     InitDialogs( nil );
  68.     InitCursor();
  69.     FlushEvents( 0, everyEvent );
  70. }
  71.  
  72. void createWindow()
  73. {
  74.     Rect        rect;
  75.     WindowPtr    window;
  76.     
  77.     SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
  78.     window = NewCWindow( 0L, &rect, "\pDefault Window Colors", true, documentProc,
  79.                             (WindowPtr)-1L, true, 0L );                        
  80.     SetPort( window );
  81.     
  82.     TextFont( geneva );
  83.     TextSize( 9 );
  84.     TextMode( srcCopy );
  85.     
  86.     gWindowCTable = (CTabHandle)NewHandle( sizeof( ColorTable )
  87.                     + ((TOTALWINCOLORS - 1) * sizeof( ColorSpec )));
  88. }
  89.  
  90. void drawWindowColors()
  91. {
  92.     int            i;
  93.     int            col, row;
  94.     Rect        rect;
  95.         
  96.     if ((gWindowCTable = (CTabHandle)GetResource( 'wctb', 0 )) != nil)
  97.     {
  98.         for (i = 0; i < TOTALWINCOLORS; i++)
  99.         {
  100.             col = 20 + ((i % 5) * 68);
  101.             row = 25 + ((i / 5) * 45);
  102.             
  103.             SetRect( &rect, col, row, col + 60, row + 20 );
  104.             RGBForeColor( &(**gWindowCTable).ctTable[i].rgb );
  105.             PaintRect( &rect ); 
  106.             
  107.             InsetRect( &rect, -2, -2 );
  108.             ForeColor( blackColor );
  109.             FrameRect( &rect );
  110.             
  111.             MoveTo( rect.left, rect.top - 3 );
  112.             DrawString( gTitles[i] );
  113.         }
  114.     }
  115. }
  116.  
  117. void doEventLoop()
  118. {
  119.     EventRecord anEvent;
  120.     WindowPtr   evtWind;
  121.     short       clickArea;
  122.     Rect        screenRect;
  123.  
  124.     for (;;)
  125.     {
  126.         if (WaitNextEvent( everyEvent, &anEvent, 0, nil ))
  127.         {
  128.             if (anEvent.what == mouseDown)
  129.             {
  130.                 clickArea = FindWindow( anEvent.where, &evtWind );
  131.                 
  132.                 if (clickArea == inDrag)
  133.                 {
  134.                     screenRect = (**GetGrayRgn ()).rgnBBox;
  135.                     DragWindow( evtWind, anEvent.where, &screenRect );
  136.                 }
  137.                 else if (clickArea == inContent)
  138.                 {
  139.                     if (evtWind != FrontWindow())
  140.                         SelectWindow( evtWind );
  141.                 }
  142.                 else if (clickArea == inGoAway)
  143.                     if (TrackGoAway( evtWind, anEvent.where ))
  144.                         return;
  145.             }
  146.             else if (anEvent.what == updateEvt)
  147.             {
  148.                 evtWind = (WindowPtr)anEvent.message;    
  149.                 SetPort( evtWind );
  150.                 
  151.                 BeginUpdate( evtWind );
  152.                 drawWindowColors();
  153.                 EndUpdate (evtWind);
  154.             }
  155.         }
  156.     }
  157. }